﻿Imports System.Web.Mvc
Imports ADODBU
Imports System.Collections.Specialized


Public Class DatapoolController
    Inherits Web.Mvc.Controller



    <AcceptVerbs(HttpVerbs.Get)> _
    Public Function ReadDataObj(ByVal Skip As Integer, ByVal Take As Integer, ByVal SortDir As String, ByVal Sort As String, ByVal target As String, ByVal param As String) As ActionResult


        If (Request.IsAjaxRequest()) Then
            Try
                Return Json(CRUDHelper.ReadDataObject(Skip, Take, SortDir, Sort, target, param).Data)
            Catch ex As Exception
                Return Nothing
            End Try


        Else

            Return RedirectToAction("Index")
        End If
    End Function

    <AcceptVerbs(HttpVerbs.Post)> _
    Public Function CreateDataObj()


        If (Request.IsAjaxRequest()) Then
            Dim Target As String

            Dim nv As NameValueCollection
            nv = ADODBU.RowClassUtil.ParseToNVCol(RowClassUtil.GetASCIIStringFromBytes(Request.BinaryRead(Request.TotalBytes)))

            Target = nv(0)
            nv.Remove(0)
            Return CRUDHelper.SaveDataObject(Target, nv)

        Else

            Return RedirectToAction("Index")
        End If
    End Function

    <AcceptVerbs(HttpVerbs.Post)> _
    Public Function UpdateDataObj()


        If (Request.IsAjaxRequest()) Then
            Dim Target As String

            Dim nv As NameValueCollection
            nv = ADODBU.RowClassUtil.ParseToNVCol(RowClassUtil.GetASCIIStringFromBytes(Request.BinaryRead(Request.TotalBytes)))
            Target = nv(0)
            nv.Remove(0)
            Return CRUDHelper.UpdateDataObject(Target, nv)
        Else

            Return RedirectToAction("Index")
        End If
    End Function


    <AcceptVerbs(HttpVerbs.Post)> _
    Public Function DeleteDataObj()


        If (Request.IsAjaxRequest()) Then
            Dim Target As String

            Dim nv As NameValueCollection
            nv = ADODBU.RowClassUtil.ParseToNVCol(RowClassUtil.GetASCIIStringFromBytes(Request.BinaryRead(Request.TotalBytes)))
            Target = nv(0)
            nv.Remove(0)
            Return CRUDHelper.DeleteDataObject(Target, nv)
        Else

            Return RedirectToAction("Index")
        End If
    End Function

   
End Class
